/*
 * TelaPrincipal.java
 *
 * Created on 23/10/2011, 15:57:19
 */
package org.acervus.gui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import org.acervus.operador.OperadorBean;

/**
 * @author Eziel Soares, Giordano Giuliano, Lenilson Regis
 */
public class TelaPrincipal extends javax.swing.JFrame {

    CadastroUsuario usuario;
    Acervo acervo;
    Emprestimo emprestimo;
    Devolucao devolucao;
    Operador operador;
    private OperadorBean operadorLogado;

    /** Creates new form TelaPrincipal */
    public TelaPrincipal() {
        initComponents();
        // Exibir a tela Maximizada
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        mnuTelaPrincipal = new javax.swing.JMenuBar();
        mnuCadastro = new javax.swing.JMenu();
        mnuUsuario = new javax.swing.JMenuItem();
        mnuAcervo = new javax.swing.JMenuItem();
        mnuOp = new javax.swing.JMenuItem();
        mnuMovimentacao = new javax.swing.JMenu();
        mnuEmprestimo = new javax.swing.JMenuItem();
        mnuDevolucao = new javax.swing.JMenuItem();
        mnuRelatorio = new javax.swing.JMenu();
        mnuMoviment = new javax.swing.JMenuItem();
        mnuPendencias = new javax.swing.JMenuItem();
        mnuSair1 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Acervus 1.0");

        mnuCadastro.setText("Cadastro");

        mnuUsuario.setText("Usuário");
        mnuUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuUsuarioActionPerformed(evt);
            }
        });
        mnuCadastro.add(mnuUsuario);

        mnuAcervo.setText("Acervo");
        mnuAcervo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuAcervoActionPerformed(evt);
            }
        });
        mnuCadastro.add(mnuAcervo);

        mnuOp.setText("Operador");
        mnuOp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuOpActionPerformed(evt);
            }
        });
        mnuCadastro.add(mnuOp);

        mnuTelaPrincipal.add(mnuCadastro);

        mnuMovimentacao.setText("Movimentação");

        mnuEmprestimo.setText("Empréstimo");
        mnuEmprestimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuEmprestimoActionPerformed(evt);
            }
        });
        mnuMovimentacao.add(mnuEmprestimo);

        mnuDevolucao.setText("Devolução");
        mnuDevolucao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuDevolucaoActionPerformed(evt);
            }
        });
        mnuMovimentacao.add(mnuDevolucao);

        mnuTelaPrincipal.add(mnuMovimentacao);

        mnuRelatorio.setText("Relatório");

        mnuMoviment.setText("Movimentação");
        mnuRelatorio.add(mnuMoviment);

        mnuPendencias.setText("Pendências");
        mnuRelatorio.add(mnuPendencias);

        mnuTelaPrincipal.add(mnuRelatorio);

        mnuSair1.setText("Sair");
        mnuSair1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuSair1ActionPerformed(evt);
            }
        });
        mnuTelaPrincipal.add(mnuSair1);

        setJMenuBar(mnuTelaPrincipal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 612, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 446, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mostrarUsuario() {

        if (usuario == null) {
            usuario = new CadastroUsuario();
            usuario.setVisible(true);
        } else {
            usuario.setVisible(true);
            usuario.setState(JFrame.NORMAL);
        }

    }

    private void mnuUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuUsuarioActionPerformed
        mostrarUsuario();
    }//GEN-LAST:event_mnuUsuarioActionPerformed

    private void mostrarAcervo() {

        if (acervo == null) {
            acervo = new Acervo();
            acervo.setVisible(true);
        } else {
            acervo.setVisible(true);
            acervo.setState(JFrame.NORMAL);
        }
    }

    private void mnuAcervoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuAcervoActionPerformed
        mostrarAcervo();
    }//GEN-LAST:event_mnuAcervoActionPerformed

    private void mostrarEmprestimo() {

        if (emprestimo == null) {
            emprestimo = new Emprestimo();
            emprestimo.setOperadorLogado(operadorLogado);
            emprestimo.setVisible(true);
        } else {
            emprestimo.setVisible(true);
            emprestimo.setState(JFrame.NORMAL);
        }
    }

    private void mnuEmprestimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuEmprestimoActionPerformed
        mostrarEmprestimo();
    }//GEN-LAST:event_mnuEmprestimoActionPerformed

    private void mostrarDevolucao() {

        if (devolucao == null) {
            devolucao = new Devolucao();
            devolucao.setVisible(true);
        } else {
            devolucao.setVisible(true);
            devolucao.setState(JFrame.NORMAL);
        }
    }

    private void mnuDevolucaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuDevolucaoActionPerformed
        mostrarDevolucao();
    }//GEN-LAST:event_mnuDevolucaoActionPerformed

    private void mostrarOperador() {

        if (operador == null) {
            operador = new Operador();
            operador.setVisible(true);
        } else {
            operador.setVisible(true);
            operador.setState(JFrame.NORMAL);
        }
    }

    private void mnuOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuOpActionPerformed
        mostrarOperador();
    }//GEN-LAST:event_mnuOpActionPerformed

    private void sair() {
        System.exit(0);
    }

    private void mnuSair1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuSair1ActionPerformed
        sair();
    }//GEN-LAST:event_mnuSair1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */

        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new TelaPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JMenuItem mnuAcervo;
    private javax.swing.JMenu mnuCadastro;
    private javax.swing.JMenuItem mnuDevolucao;
    private javax.swing.JMenuItem mnuEmprestimo;
    private javax.swing.JMenuItem mnuMoviment;
    private javax.swing.JMenu mnuMovimentacao;
    private javax.swing.JMenuItem mnuOp;
    private javax.swing.JMenuItem mnuPendencias;
    private javax.swing.JMenu mnuRelatorio;
    private javax.swing.JMenu mnuSair1;
    private javax.swing.JMenuBar mnuTelaPrincipal;
    private javax.swing.JMenuItem mnuUsuario;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the operadorLogado
     */
    public OperadorBean getOperadorLogado() {
        return operadorLogado;
    }

    /**
     * @param operadorLogado the operadorLogado to set
     */
    public void setOperadorLogado(OperadorBean operadorLogado) {
        this.operadorLogado = operadorLogado;
    }
}
